﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HR.Appointments.Service;

public partial class CompanyBooking : EmployeePage
{
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckCredentials();
        _imgConfirm.Visible = IsLoggedIn;
        if (!IsPostBack)
        {

            ListActivities();
            ListWorkstations();
        }
    }

    protected void _btnFindTime_Click(object sender, EventArgs e)
    {
        string activityId = _ddlAction.SelectedValue.ToString();
        string workstationId = _ddlWorkstation.SelectedValue.ToString();
        Server.Transfer(string.Format("~/VacantSlots.aspx?ActivityId={0}&WorkstationId={1}",
            activityId,workstationId),true);
    }

    protected void _lbtnLogoff_PreRender(object sender, EventArgs e)
    {
        var _message = "Viltu útskrá?";
        Page.ClientScript.RegisterClientScriptBlock(GetType(),
          "__doAlert",
          @"<script language=""javascript"">" + Environment.NewLine +
          "function __doConfirm(btn){" + Environment.NewLine +
            @"var answer = confirm(""" + _message + @""");" + Environment.NewLine +
            "if (answer){" + Environment.NewLine +
              "return true;}" + Environment.NewLine +
            "else{" + Environment.NewLine +
              "return false;}}" + Environment.NewLine +
            "</script>");
        var button = (System.Web.UI.WebControls.LinkButton)sender;
        button.CausesValidation = false;
        button.Attributes["onclick"] = "return __doConfirm(this);";

        base.OnPreRender(e);
    }
    #endregion

    #region Link Transfer
    protected void _lbtnLogoff_Click(object sender, EventArgs e)
	{
        this.Validate();
        if (IsValid)
        {
            LogOff();
            Server.Transfer("~/Company.aspx", true);
        }
	}

    protected void _lbtnDisplayAllOrders_Click(object sender, EventArgs e)
    {
		Server.Transfer("~/DisplayAllOrders.aspx",true);
    }
    protected void _lbtnConfig_Click(object sender, EventArgs e)
    {
		Server.Transfer("~/Config.aspx",true);
    }

	protected void _ibmHomePage_Click(object sender, ImageClickEventArgs e)
	{
        if (!IsPostBack || (e.X != 0 && e.Y != 0))
        {
            Server.Transfer("~/Company.aspx",true);
        }
	}
	protected void _lbtnTakeTime_Click(object sender, EventArgs e)
	{
		Server.Transfer("~/DisplayTakeTime.aspx", true);
	}
    protected void _lbtnDisplayOrdersByDate_Click(object sender, EventArgs e)
    {
        Server.Transfer("~/DislpayOrdersByDate.aspx", true);
    }
    protected void _lbtnDisplayOpenHours_Click1(object sender, EventArgs e)
    {
        Server.Transfer("~/DisplayOpenHours.aspx", true);
    }
    #endregion

    #region Private List Methods
    protected void ListActivities()
    {
        _ddlAction.DataSource = Facade.Employee().GetActivities(
            GetCompanyIdFromCookie());
        _ddlAction.DataBind();

    }

    protected void ListWorkstations()
    {
        _ddlWorkstation.DataSource = Facade.Employee().GetWorkstations(
           GetCompanyIdFromCookie());
        _ddlWorkstation.DataBind();
    }
    #endregion

    
}
